package _08TreeMap练习_Comparator接口;

import _07TreeMap练习_Comparable接口.Student;

import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class DemoTreeMap {
    public static void main(String[] args) {
        Student a = new Student("张三", "男", 21);
        Student b = new Student("李四", "男", 22);
        Student c = new Student("张三", "男", 20);
        Student d = new Student("张三", "男", 20);

        TreeMap<_07TreeMap练习_Comparable接口.Student,String> map =new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });

        map.put(a,"北京");
        map.put(b,"广州");
        map.put(c,"上海");
        map.put(d,"新疆");

        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+value);
        }


    }
}
